﻿using Infrastructure.WebApi;

namespace Infrastructure.DDD
{
    public static class EntityExtension
    {
        /// <summary>
        /// 软删除
        /// </summary>
        public static void SoftDelete<T>(this T t) where T : Entity
        {
            t.IsDelete = true;
            t.UpdateTime = DateTime.Now;
        }
        /// <summary>
        /// 软删除
        /// </summary>
        public static void SoftDeleteRange<T>(this List<T> list) where T : Entity
        {
            foreach (var t in list)
            {
                t.IsDelete = true;
                t.UpdateTime = DateTime.Now;
            }
        }
        /// <summary>
        /// 若数据不存在则抛出提示
        /// </summary>
        public static void CheckNull<T>(this T t) where T : class
        {
            if (t == null) BusinessException.Throw("数据不存在");
        }
    }
}
